package window;


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import javax.swing.SwingConstants;

import dao.TeacherDao;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class IUpdatepage {
	String id="";
	String cid="";
	public JFrame iUpdatepageFrame;
	private JTextField textField;

	/**
	 * Launch the application.
	 */

	/**
	 * Create the application.
	 */
	public IUpdatepage(String id) {
		this.id=id;
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		iUpdatepageFrame = new JFrame();
		iUpdatepageFrame.setBounds(-7, 0, 1380, 736);
		iUpdatepageFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		iUpdatepageFrame.getContentPane().setLayout(null);
		
		JLabel label = new JLabel("教师信息修改");
		label.setHorizontalAlignment(SwingConstants.CENTER);
		label.setForeground(Color.DARK_GRAY);
		label.setFont(new Font("宋体", Font.BOLD, 30));
		label.setBounds(0, 50, 1364, 31);
		iUpdatepageFrame.getContentPane().add(label);
		
		JMenuBar menuBar = new JMenuBar();
		menuBar.setBounds(0, 0, 1364, 23);
		iUpdatepageFrame.getContentPane().add(menuBar);
		
		JMenu mnNewMenu = new JMenu("操作(ALT+1)");
		mnNewMenu.setHorizontalAlignment(SwingConstants.CENTER);
		mnNewMenu.setFont(new Font("幼圆", Font.PLAIN, 15));
		mnNewMenu.setForeground(Color.DARK_GRAY);
		mnNewMenu.setMnemonic('1');
		menuBar.add(mnNewMenu);
		
		JMenuItem menuItem = new JMenuItem("返回(F)");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				TeacherHomepage th=new TeacherHomepage(id);
				th.teacherHomepageFrame.setVisible(true);
				iUpdatepageFrame.dispose();
			}
		});
		menuItem.setFont(new Font("幼圆", Font.PLAIN, 13));
		menuItem.setForeground(Color.DARK_GRAY);
		menuItem.setMnemonic('F');
		mnNewMenu.add(menuItem);
		
		JMenuItem mntme = new JMenuItem("退出登录(E)");
		mntme.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Login lg=new Login();
				lg.LoginFrame.setVisible(true);
				iUpdatepageFrame.dispose();
			}
		});
		mntme.setMnemonic('E');
		mntme.setForeground(Color.DARK_GRAY);
		mntme.setFont(new Font("幼圆", Font.PLAIN, 13));
		mnNewMenu.add(mntme);
		
		JLabel lblNewLabel_1 = new JLabel("欢迎你，亲爱的");
		lblNewLabel_1.setForeground(Color.DARK_GRAY);
		lblNewLabel_1.setFont(new Font("幼圆", Font.PLAIN, 12));
		lblNewLabel_1.setBounds(10, 37, 90, 15);
		iUpdatepageFrame.getContentPane().add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("New label");
		lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_2.setText(id);
		lblNewLabel_2.setForeground(Color.DARK_GRAY);
		lblNewLabel_2.setFont(new Font("幼圆", Font.BOLD, 13));
		lblNewLabel_2.setBounds(97, 37, 75, 15);
		iUpdatepageFrame.getContentPane().add(lblNewLabel_2);
		
		JLabel label1 = new JLabel("工号：");
		label1.setForeground(Color.DARK_GRAY);
		label1.setFont(new Font("幼圆", Font.BOLD, 15));
		label1.setBounds(540, 140, 80, 43);
		iUpdatepageFrame.getContentPane().add(label1);
		
		JButton button = new JButton("提交");
		
		textField = new JTextField();
		textField.setDocument(new MyDocument(11));
		textField.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				if(e.getKeyCode()==KeyEvent.VK_ENTER)
					button.doClick();
			}
		});
		textField.setColumns(10);
		textField.setBounds(626, 151, 165, 21);
		iUpdatepageFrame.getContentPane().add(textField);
		
		JLabel label_8 = new JLabel("教师信息修改");
		label_8.setHorizontalAlignment(SwingConstants.CENTER);
		label_8.setForeground(Color.DARK_GRAY);
		label_8.setFont(new Font("宋体", Font.BOLD, 30));
		label_8.setBounds(0, 50, 1364, 31);
		iUpdatepageFrame.getContentPane().add(label_8);
		

		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(textField.getText().length()>0) {
					if(TeacherDao.checkId(textField.getText())) {
						cid=textField.getText();
						Updatepage up=new Updatepage(id,cid);
						up.updatepageFrame.setVisible(true);
						iUpdatepageFrame.dispose();
					}
					else 
						JOptionPane.showMessageDialog(null, "工号不存在！", "error！", JOptionPane.ERROR_MESSAGE);	
				}
				else JOptionPane.showMessageDialog(null, "请输入工号！", "error！", JOptionPane.ERROR_MESSAGE);	
			}
		});
		button.setForeground(Color.DARK_GRAY);
		button.setFont(new Font("幼圆", Font.BOLD, 16));
		button.setBounds(620, 580, 130, 35);
		iUpdatepageFrame.getContentPane().add(button);
		
		JLabel label_1 = new JLabel("，请输入要修改的教师信息工号！");
		label_1.setForeground(Color.DARK_GRAY);
		label_1.setFont(new Font("幼圆", Font.PLAIN, 12));
		label_1.setBounds(170, 37, 202, 15);
		iUpdatepageFrame.getContentPane().add(label_1);
	}
}
